//
// Created by ASUS on 2024/1/25.
//
#include <bits/stdc++.h>
using namespace std;

template<typename T>
class BIT{
private:
	vector<T> tree;
public:
	BIT(int n):tree(n){}

	void clear(){
		fill(tree.begin(), tree.end(),0);
	}

	inline int lowbit(int i){
		return i&-i;
	}

	void add(int i,T x){
		while(i<tree.size()){
			tree[i]+=x;
			i+= lowbit(i);
		}
	}

	T query(int i){
		T res=0;
		while(i>0){
			res+=tree[i];
			i-= lowbit(i);
		}
		return res;
	}

	T query(int l,int r){
		return query(r)- query(l-1);
	}
};

template<typename T>
class Discretization{
private:
	vector<T> b;
public:
	Discretization(vector<T>& a,bool used){
		if(used){
			b=a;
			sort(b.begin(), b.end());
			b.erase(unique(b.begin(), b.end()),b.end());//排序去重
		}else{
			sort(a.begin(), a.end());
			a.erase(unique(a.begin(), a.end()),a.end());//排序去重
			b=a;
		}
	}

	int size(){
		return b.size();
	}

	int id(T x){
		return lower_bound(b.begin(), b.end(), x) - b.begin();
	}

	int operator<(T x){
		return lower_bound(b.begin(), b.end(),x) - b.begin();
	}
	int operator<=(T x){
		return upper_bound(b.begin(), b.end(),x) - b.begin();
	}
	int operator>(T x){
		return upper_bound(b.begin(), b.end(),x) - b.begin()+1,b.size();
	}
	int operator>=(T x){
		return lower_bound(b.begin(), b.end(),x) - b.begin()+1,b.size();
	}
};

int main(){

	vector<int> a;//原始数组
	int diff=1;
	int n=a.size();
	//离散化
	auto b=a;
	sort(b.begin(), b.end());
	b.erase(unique(b.begin(), b.end()),b.end());//排序去重

	long ans=0L;
	BIT<int> t(n+1);//下标从1开始
	for (int x : a) {
		ans += t.query(upper_bound(b.begin(), b.end(), x + diff) - b.begin());
		t.add(lower_bound(b.begin(), b.end(), x) - b.begin() + 1,1);
	}
	return ans;
}
/* 查询<x的元素个数 t.query(lower_bound(b.begin(), b.end(),x) - b.begin());
 * 查询<=x的元素个数 t.query(upper_bound(b.begin(), b.end(),x) - b.begin());
 * 查询>x的元素个数 t.query(upper_bound(b.begin(), b.end(),x) - b.begin()+1,b.size());
 * 查询>=x的元素个数 t.query(lower_bound(b.begin(), b.end(),x) - b.begin()+1,b.size());
 * */